filename = 'noten_sample.gif';
input = ~imread(filename);
%input = flipud(input);

[height,width] = size(input);

rhoMax = round(norm([height width]));
rhoRange = -rhoMax:1:rhoMax;

thetaBins = 300;
thetaRange = 0:pi/thetaBins:pi-pi/thetaBins;

accu = zeros(numel(rhoRange),thetaBins);

%speed up !!!
cosine = (1:width)'*cos(thetaRange);
sine = (1:height)'*sin(thetaRange);

[indy,indx] = find(input);

for i=1:size(indx)
    for theta=1:thetaBins
        rho = round(cosine(indx(i),theta)+sine(indy(i),theta));
       
        if(rho+max_rho > 0 && rho+max_rho < numel(rhoRange))
            accu(rho+max_rho,theta) = accu(rho+max_rho,theta)+1;
        end
    end
end

accu = accu ./ max(accu(:));
accu = im2bw(accu,0.5);

%imshow(accu);

[rho,theta] = find(accu);
theta = theta .* pi/thetaBins;
rho = rho - max_rho;

rho
theta * 57.3

input = imread(filename);
imshow(input);
hold on;
%r = size(out,2);
for i=1:numel(rho)
    drawPolarLine(out,theta(i),rho(i));
end
hold off;
